<?php defined('SYSPATH') or die();?>

    <div class="page out" id="orderList">
        <div class="header_top">
            <a class="back-link-icon" href="javascript:;" data-rel="back"></a>
            <h1 class="page-title-bar">订单列表</h1>
        </div>
        <!-- 公用顶部 -->
        <div class="page-content" id="order_list">
            <div class="tip-search-wrap">
                <form name="" id="search-form" class="fenxiao_order_search_fm" action="javascript:;">
                    <div class="search-bar">
                        <i class="search-icon"></i>
                        <input type="search" name=""  id="order_keyword" class="search-text" placeholder="请输入分销商/客户名称" />
                    </div>
                </form>
            </div>
            <div class="search-bg-layer"></div>
            <div class="search-filter-bar">
                <div class="search-tab-item col-4">
                    <strong class="tab-name">全部订单</strong>
                    <ul class="item-list" id="rank_type">
                        <li value="0">全部订单</li>
                        <li value="1">我的第一级分销订单</li>
                        <li value="2">我的第二级分销订单</li>
                        {if $level_num==3}
                        <li value="3">我的第三级分销订单</li>
                        {/if}
                        <li value="4">自购佣金订单</li>
                    </ul>
                </div>
                <div class="search-tab-item col-4">
                    <strong class="tab-name">订单状态</strong>
                    <ul class="item-list" id="status_type">
                        <li>所有订单</li>
                        {loop $status_names $key $status}
                         <li value="{$key}">{$status}</li>
                        {/loop}

                    </ul>
                </div>
                <div class="search-tab-item col-4">
                    <strong class="tab-name">产品类型</strong>
                    <ul class="item-list" id="product_type">
                        <li>所有产品</li>
                        {loop $products $product}
                          <li value="{$product['id']}">{$product['modulename']}</li>
                        {/loop}
                    </ul>
                </div>
                <div class="search-tab-item col-4">
                    <strong class="tab-name">排序</strong>
                    <ul class="item-list" id="order_type">
                        <li value="1">下单时间倒序</li>
                        <li value="2">收益由高到低</li>
                        <li value="3">收益由低到高</li>
                    </ul>
                </div>
            </div>
            <div class="search-list-wrap">
                <ul class="search-order-list" id="order_list_con">

                </ul>
                <!-- 订单列表 -->
                <div class="null-order-box hide" id="order_list_none">
                    <div class="info">
                        <i class="icon"></i>
                        <p class="txt">您还没有订单，马上<a class="link" href="{$cmsurl}fenxiao/product">分销产品</a>赚取佣金</p>
                    </div>
                </div>
                <div class="no-info-bar" id="fenxiao_order_no_more" style="display: none;">没有更多结果了！</div>

                <!-- 空订单 -->
            </div>
        </div>
    </div>
    <script>

     (function()
     {
         var SITEURL = "{URL::site()}";
         var CURRENCY_SYMBOL="{Currency_Tool::symbol()}";
         var gbl_page=1;
         var gbl_is_loading=false;
         $("#order_list .search-tab-item .tab-name").on("click",function(){
             $(this).parent(".search-tab-item").addClass("cur-tab-item").siblings().removeClass("cur-tab-item");
             $("#order_list .search-list-wrap").css("overflow","hidden");
             $("#order_list .search-bg-layer").show();
         });

         $("#order_list .search-tab-item .item-list>li").on("click",function(){
             $(this).addClass("on").siblings().removeClass("on");
             $(this).parents(".search-tab-item").removeClass("cur-tab-item");
             $("#order_list .search-list-wrap").css("overflow","auto");
             $("#order_list .search-bg-layer").hide();
             gbl_page=1;
             fenxiao_get_orders(1);
         });

         $("#order_list .search-bg-layer").on("click",function(){
             $(this).hide();
             $("#order_list .search-tab-item").removeClass("cur-tab-item");
             $("#order_list .search-list-wrap").css("overflow","auto");
         })

         $("#order_list .search-list-wrap").scroll(function(){
             var scroll_top=$('#order_list .search-list-wrap').scrollTop();
             if(scroll_top+3>=($("#order_list .search-list-wrap")[0].scrollHeight - $('#order_list .search-list-wrap').outerHeight()))
             {
                 if(gbl_is_loading==false)
                 {
                     fenxiao_get_orders(gbl_page+1);
                 }
             }
         });

         //搜索按钮
         $("#order_list .search-icon").click(function(){
             gbl_page=1;
             fenxiao_get_orders(1);
         })

         $(".fenxiao_order_search_fm").submit(function(){
             fenxiao_get_orders(1);
         });


         //获取订单列表
         fenxiao_get_orders(1);


         //获取订单列表函数
         function fenxiao_get_orders(page)
         {
             gbl_is_loading=true;
             var rank=$("#rank_type li.on").attr('value');
             var status=$("#status_type li.on").attr('value');
             var typeid=$("#product_type li.on").attr('value');
             var order=$("#order_type li.on").attr('value');
             var keyword=$("#order_keyword").val();

             var params={
                 rank:rank,
                 status:status,
                 typeid:typeid,
                 order:order,
                 keyword:keyword,
                 page:page
             }
             $.ajax({
                 url:SITEURL+'fenxiao/ajax_get_orders',
                 type:'POST', //GET
                 data:params,
                 dataType:'json',
                 success:function(data,textStatus,jqXHR){
                     gbl_is_loading=false;
                     if(data.status)
                     {
                         var html='';

                         for(var i in data.list)
                         {
                             var row=data.list[i];

                             var commission_str=row['commission_type']==1?'佣金比例：'+row['commission']:'佣金：'+CURRENCY_SYMBOL+row['commission'];
                             var parent_member_nickname = row['parent_member']?row['parent_member']['nickname']:'匿名';

                             html+='<li><div class="info-t">'+
                         '<span class="date">'+row['addtime']+'</span>'+
                         '<span class="status fr c-dd2">'+row['status_name']+'</span>'+
                         '</div><div class="info-m">'+
                         '<div class="pic"><img src="'+row['litpic']+'" alt="'+row['productname']+'"/></div>'+
                         '<div class="nr">'+
                         '<h4 class="name">'+row['productname']+'</h4>'+
                         '<p class="data">订单号：'+row['ordersn']+'</p>'+
                         '<p class="data">客户：'+row['member']['nickname']+'</p>'+
                         '</div> </div><div class="info-b"><p>'+
                         '<span class="item">应付总额：'+CURRENCY_SYMBOL+row['totalprice']+'</span>'+
                        // '<span class="item fr">'+commission_str+'</span>'+
                         '</p> <p>'+
                         '<span class="item">分销商：'+parent_member_nickname+'</span>';

                          if(row['status']==5)
                          {
                              html += '<span class="item fr c-f60">收益：' + CURRENCY_SYMBOL + row['fenxiao_amount'] + '</span>';
                          }
                          else
                          {
                              html += '<span class="item fr c-f60">待结算：' + CURRENCY_SYMBOL + row['commission_amount'] + '</span>';
                          }

                          html+= '</p></div></li>';
                         }
                         if(page==1)
                         {
                             $("#order_list_con").children().remove();
                         }

                         if(data.list.length<10)
                         {
                             $("#fenxiao_order_no_more").show();
                         }


                         $("#order_list_con").append(html);
                         if($("#order_list_con li").length==0)
                         {
                             $("#order_list_none").show();
                             $("#fenxiao_order_no_more").hide();
                         }
                         else
                         {
                             $("#order_list_none").hide();
                         }

                         if(html!='')
                         {
                             gbl_page = page;
                         }
                     }
                 }
             })


         }
     })()


